package com.dzm.core.controller.api;


import com.dzm.common.result.R;
import com.dzm.common.util.JwtUtils;
import com.dzm.core.hfb.RequestHelper;
import com.dzm.core.service.IUserBindService;
import com.dzm.core.vo.UserBindVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 用户绑定表 前端控制器
 * </p>
 *
 * @author Dzm
 * @since 2024-09-20
 */
@RestController
@RequestMapping("/api/core/userBind")
public class UserBindController {

    @Autowired
    private IUserBindService userBindService;

    @PostMapping("/auth/bind")
    public R bind(@RequestBody UserBindVo bindVo, HttpServletRequest request) {
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        String formStr = userBindService.bind(bindVo, userId);

        return R.ok().data("formStr", formStr);
    }

    @PostMapping("/notify")
    public R bindNotify(HttpServletRequest request) {
        Map<String, String[]> parameterMap = request.getParameterMap();
        Map<String, Object> map = RequestHelper.switchMap(parameterMap);
        userBindService.bindNotify(map);

        return R.ok().message("用户绑定成功！");
    }
}
